<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ES6中的迭代器</title>
  </head>
  <body>
    <script>
      const myObj = {
        code: 200,
        value: "123",
        list: ["aaaaa", "bbb", "cc"],
        [Symbol.iterator]: function () {
          let index = 0;
          return {
            next: () => {
              if (index < this.list.length) {
                return {
                  value: this.list[index++],
                  done: false,
                };
              } else {
                return {
                  value: undefined,
                  done: true,
                };
              }
            },
          };
        },
      };

      for (let o of myObj) {
        console.log(o);
      }
    </script>
  </body>
</html>
